<?php


namespace app\shopConsole\controller;



use app\BaseController;


use app\console\validate\AuthValidate;
use app\lib\exception\ParamException;
use app\shopConsole\service\AuthService;
use think\App;
use app\Request;
use think\exception\ValidateException;

class AuthController extends BaseController
{

    public function login(Request $request)
    {
        $authService = new AuthService();

        $param = $request->param(['username', 'password']);
        try
        {
            validate(AuthValidate::class)
                ->scene('login')
                ->check($param);
        } catch (ValidateException $e) {
            throw new ParamException($e->getMessage());
        }

        $token = $authService->login($param['username'], $param['password']);
        return $this->returnJson(['token' => $token]);
    }
}